import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support import wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait


class UserAddPage:

    def __init__(self, driver):

        self.driver = driver  # 从 login_page 获取 driver

    def adduser_page(self, username, password, realname, phonenum, email):
        self.driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        # time.sleep(1)
        # 点击用户信息
        self.driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        # time.sleep(1)#
        # 点击新增按钮
        self.driver.find_element(By.XPATH, '//*[@id="user_add_modal_btn"]').click()
        time.sleep(1)
        # 输入账户名
        item2 = wait.WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located( (By.XPATH,'//*[@id="username_add_input"]')))
        item2.send_keys(f'{username}')
        # driver.find_element(By.XPATH,'//*[@id="username_add_input"]').send_keys(f'{username}')
        # time.sleep(1)
        # 输入密码
        self.driver.find_element(By.XPATH, '//*[@id="password_add_input"]').send_keys(f'{password}')
        # time.sleep(1)
        # 输入真实姓名
        self.driver.find_element(By.XPATH, '//*[@id="realname_add_input"]').send_keys(f'{realname}')
        # time.sleep(1)
        self.driver.find_element(By.XPATH, '//*[@id="phone_add_input"]').send_keys(f'{phonenum}')
        # time.sleep(1)
        self.driver.find_element(By.XPATH, '//*[@id="email_add_input"]').send_keys(f'{email}')
        # time.sleep(1)
        #点击保存
        self.driver.find_element(By.XPATH, '//*[@id="user_save_btn"]').click()
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, '//div[starts-with(@id,"jconfirm-")]/div'))
        )
        return self.driver

        # return self.adduser_success_get_massage()
    """
        获取 新增用户成功 的信息
    """
    def adduser_success_get_massage(self):

        return self.driver.find_element(By.XPATH,'//div[starts-with(@id,"jconfirm-")]/div').text #成功时显示： 用户新增成功!

    """
        获取到 用户名为空 的信息
    """

    def adduser_none_name_get_massage(self):
        return self.driver.find_element(By.XPATH,'//*[@id="userAddModal"]/div/div/div[2]/form/div[1]/div[1]/span').text

    """
        获取到 密码为空 的信息
    """
    def adduser_none_password_get_massage(self):
        return self.driver.find_element(By.XPATH,'//*[@id="userAddModal"]/div/div/div[2]/form/div[2]/div[1]/span').text

    """
        获取到 真实姓名不合法 的信息
    """
    def adduser_illegal_realname_get_massage(self):
        return self.driver.find_element(By.XPATH,'//*[@id="userAddModal"]/div/div/div[2]/form/div[3]/div/span').text

    """
        获取到 手机号不合法 的信息
    """
    def adduser_illegal_phonenum_get_massage(self):
        return self.driver.find_element(By.XPATH,'//*[@id="userAddModal"]/div/div/div[2]/form/div[4]/div/span').text

    """
        获取到 邮箱不合法 的信息
    """
    def adduser_illegal_email_get_massage(self):
        return self.driver.find_element(By.XPATH,'//*[@id="userAddModal"]/div/div/div[2]/form/div[5]/div/span').text


    #     # self.driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[2]/a').click()
    #     # self.driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
    #     # self.driver.find_element(By.XPATH,
    #     # 							 '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
    # time.sleep(1)
    # MyPassword.pas_in(self.driver)

    # def login_success_get_massage(self):
    #     return self.driver.find_element(By.XPATH, "/html/body/div/div/aside/div[1]/a").text
    #
    # def login_name_error_get_massage(self):
    #     return self.driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[1]/span[1]").text
    #
    # def login_password_error_get_massage(self):
    #     return self.driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/span[1]").text
    #




















